package com.text.day3_2;

import java.io.File;
import java.util.LinkedList;

public class QueDemo {
    public static void main(String[] args) {

        String filepath = "D:\\txt\\java\\java2306\\code\\java2306\\src\\com\\text\\day3_2\\abc";
        // java中代表目录和文件的都是File对象
        File file = new File(filepath);
        System.out.println(file.isDirectory()); // true

        System.out.println(file.getName()); // 打印目录的名字

        // 获取一个目录下的内容

        LinkedList<String> list = new LinkedList<>();
        list.offer(filepath);
        while (list.size() > 0) {
            niHao(list);
        }


//        File file1 = new File("D:\\abc\\a");
//        File[] files1 = file1.listFiles();
//        for (int i = 0; i < files1.length; i++) {
//            System.out.println(files1[i].getName());
//        }

    }

    public static void niHao(LinkedList<String> list) {
        String filepath = list.poll();
        File file = new File(filepath);
        File[] files = file.listFiles();
        for (int i = 0; i < files.length; i++) {
            System.out.println(files[i].getName());
            File file2 = new File(filepath + "\\" + files[i].getName());
            if (file2.isDirectory()) {
                list.offer(filepath + "\\" + files[i].getName());
            }
        }
    }


}
